package com.mozz.finally_work.servlet;

import com.mozz.finally_work.dao.CollectionDao;
import com.mozz.finally_work.dao.SubscribeDao;
import com.mozz.finally_work.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/*取消关注*/
@WebServlet(name = "UnSubscribeServlet", value = "/UnSubscribeServlet")
public class UnSubscribeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String targetId = request.getParameter("targetId");
        String userId = request.getParameter("userId");
        /*调用dao取消收藏*/
        SqlSession session = MybatisUtils.getSession();
        SubscribeDao dao = session.getMapper(SubscribeDao.class);
        Integer integer = dao.unSubscribeUser(userId, targetId);
        session.commit();
        session.close();
        response.sendRedirect("UserSubscribeServlet?userId="+userId);
    }
}
